<?php

class Utilitarios_ModulosController extends Zend_Rest_Controller {

	public function init() {
		/* Initialize action controller here */
		$ajaxContext = $this->_helper->contextSwitch();
		$ajaxContext->setAutoJsonSerialization(true);
		$ajaxContext
		->addActionContext('index', array('json'))
		->addActionContext('get', array('json'))
		->addActionContext('post', array('json'))
		->addActionContext('put', array('json'))
		->addActionContext('delete', array('json'))
		->initContext('json');
	}

	public function indexAction(){
		$model_modulo=new Application_Model_Utilitarios_Modulo();
		$modulo=$model_modulo->index($this->getRequest()->getParam('filter'), $this->getRequest()->getParam('start'), $this->getRequest()->getParam('limit'), $this->getRequest()->getParam('sort'));

		$this->view->success=$modulo['success'];
		$this->view->mensagem=$modulo['message'];
		$this->view->data=$modulo['data'];
	}

	public function getAction(){
	}

	public function postAction(){
		$post = Zend_Json::decode($this->getRequest()->getRawBody());
		
		$model_modulo=new Application_Model_Utilitarios_Modulo();
		$modulo=$model_modulo->post($post);
		
		$this->view->success=$modulo['success'];
		$this->view->mensagem=$modulo['message'];
		$this->view->data=$modulo['data'];
	}

	public function putAction(){
		$id = $this->getRequest()->getParam('id');
		$post = Zend_Json::decode($this->getRequest()->getRawBody());
		
		$model_modulo=new Application_Model_Utilitarios_Modulo();
		$modulo=$model_modulo->put($id,$post);
		
		$this->view->success=$modulo['success'];
		$this->view->mensagem=$modulo['message'];
		$this->view->data=$modulo['data'];
	}

	public function deleteAction(){
		$id = $this->getRequest()->getParam('id');
		
		$model_modulo=new Application_Model_Utilitarios_Modulo();
		$modulo=$model_modulo->delete($id);
		
		$this->view->success=$modulo['success'];
		$this->view->mensagem=$modulo['message'];
		$this->view->data=$modulo['data'];
	}

}